Reuse direct reverse mode autodiff specializations for known laplace distributions#3291
Reuse direct reverse mode autodiff specializations for known laplace distributions#3291ishaan-arora-1 wants to merge 2 commits intostan-dev:developfrom
Conversation
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
|
This is cool! Can you do a benchmark of this vs the old version to see what the difference in performance is? |
|
Also, do the benchmark first, but if the benchmark works then I think I'd prefer having two overloads instead of an if constexpr here as the if statements / nested if statements can be a bit much for readability. See the example below https://godbolt.org/z/bjhrdKo4E I have this repo for benchmarking stan stuff that may be useful, but we also have google benchmark |
I've implemented a fix for the issue. I found that we can bypass the expensive nested autodiff by providing specialized
diff()andthird_diff()methods directly within the likelihood functors likeneg_binomial_2_log.I think this should be a good fix considering we've added type traits (e.g.,
has_custom_diff) to compile-time dispatch these specialized methods without breaking the generic autodiff fallback for other distributions. Computations derived from the original implementation (commit 3f310e7) were adapted to match the current API structure, which should bring back the performance gains.Resolves #3287